package PHANVANVUONG.SWING;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import HOANGVIETANH_EX2.Views;

import java.awt.Color;
import javax.swing.UIManager;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import java.awt.Font;
import javax.swing.border.CompoundBorder;
import javax.swing.JButton;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

@SuppressWarnings({ "unused", "serial" })
public class Demo extends JFrame {

	private JPanel contentPane;
	private JTextField txtTk;
	private JPasswordField txtPW;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Demo frame = new Demo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Demo() {
		setIconImage(Toolkit.getDefaultToolkit()
				.getImage("C:\\Users\\bongm\\Downloads\\10460411_570547203055938_6780378632843535140_n.jpg"));
		setTitle("Phần mềm quản lý nhân sự");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 458, 235);
		contentPane = new JPanel();
		contentPane.setBorder(new TitledBorder(new CompoundBorder(null, UIManager.getBorder("TitledBorder.border")),
				"Th\u00F4ng tin \u0111\u0103ng nh\u1EADp", TitledBorder.LEADING, TitledBorder.TOP, null,
				new Color(255, 0, 0)));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel lblNewLabel = new JLabel("Tên tài khoản");
		lblNewLabel.setFont(new Font("Cambria", Font.PLAIN, 14));
		lblNewLabel.setBounds(36, 72, 100, 18);
		contentPane.add(lblNewLabel);

		JLabel lblMtKhu = new JLabel("Mật khẩu");
		lblMtKhu.setFont(new Font("Cambria", Font.PLAIN, 14));
		lblMtKhu.setBounds(36, 115, 100, 18);
		contentPane.add(lblMtKhu);

		txtTk = new JTextField();
		txtTk.setBackground(Color.GREEN);
		txtTk.setBounds(170, 72, 229, 20);
		contentPane.add(txtTk);
		txtTk.setColumns(10);

		txtPW = new JPasswordField();
		txtPW.setBackground(Color.CYAN);
		txtPW.setBounds(170, 113, 229, 20);
		contentPane.add(txtPW);

		JButton bLogin = new JButton("Đăng nhập");
		bLogin.addActionListener(new ActionListener() {
			@SuppressWarnings("deprecation")
			public void actionPerformed(ActionEvent arg0) {
				if (txtTk.getText().isEmpty()) {
					JOptionPane.showMessageDialog(getParent(), "Yêu cầu phải nhập vào thông báo", "Lỗi",
							JOptionPane.WARNING_MESSAGE);
				} else if (txtPW.getText().isEmpty()) {
					JOptionPane.showMessageDialog(getParent(), "Yêu cầu chuyên gia phải nhập vào password", "Lỗi",
							JOptionPane.WARNING_MESSAGE);
				} else {
					UserEntity objU = new UserEntity();
					objU.setUserName(txtTk.getText());
					objU.setPassWord(txtPW.getText());
					Controllers objC = new Controllers(objU);
					if (objC.CheckUserInfor()) {
						JOptionPane.showMessageDialog(getParent(), "Chúc mừng chuyên gia", "Thông báo",
								JOptionPane.INFORMATION_MESSAGE);
					} else {
						JOptionPane.showMessageDialog(getParent(), "Rất tiếc thưa chuyên gia", "Thông báo",
								JOptionPane.ERROR_MESSAGE,
								new ImageIcon(Views.class.getResource("/NGUYENMINHHIEU/SWING_DEMO/ICONS/cancel.gif")));
					}
				}
			}
		});
		bLogin.setIcon(new ImageIcon(
				"D:\\Development\\IMIC\\4. SLIDE & EXCERCISES\\2. JAVA PROGRAMMING\\PART07 - SWING GUI APPLICATIONS\\images\\contacts.png"));
		bLogin.setBackground(Color.RED);
		bLogin.setBounds(170, 151, 130, 23);
		contentPane.add(bLogin);

		JButton bThoat = new JButton("Thoát");
		bThoat.setIcon(new ImageIcon(Demo.class.getResource("/NGUYENMINHHIEU/SWING_DEMO/ICONS/cancel.gif")));
		bThoat.setBackground(Color.MAGENTA);
		bThoat.setBounds(310, 151, 89, 23);
		contentPane.add(bThoat);

		JLabel lblNewLabel_1 = new JLabel("Vui lòng điền thông tin đầy đủ");
		lblNewLabel_1.setFont(new Font("Cambria", Font.PLAIN, 14));
		lblNewLabel_1.setBounds(36, 30, 333, 20);
		contentPane.add(lblNewLabel_1);
	}
}
